package edu.chl.da.ejb.ctrl;

import edu.chl.da.ejb.core.Account;
import edu.chl.da.ejb.core.Customer;
import edu.chl.da.ejb.persistency.ICustomerFacade;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Max
 */
@Stateless
public class ManageCustomer implements IManageCustomer {
    @EJB
    ICustomerFacade icf;

    @EJB
    IManageReservation imr;

    @Override
    public Customer registerNewCustomer(String username, String password,String email, String firstname, String lastname) {
        Customer c = new Customer();
        Account a = new Account();
        a.setUsername(username);
        a.setPassword(password);
        a.setEmail(email);
        a.setFirstname(firstname);
        a.setLastname(lastname);
        c.setAccount1(a);
        c.setAccount(username);
        a.setCustomer(c);
        icf.create(c);
        return c;
    }

    @Override
    public Customer getCustomer(String username) {
        return icf.find(username);
    }

    @Override
    public Customer editCustomer(Customer customer) {
        if(customer == null){
            throw new NullPointerException("Customer is null");
        }
        icf.edit(customer);
        return customer;
    }

    @Override
    public boolean removeCustomer(Customer customer) {
        icf.remove(customer);
        return true;
    }

    @Override
    public List<Customer> getCustomerList() {
        return icf.findAll();

    }
}
